import request from '@/utils/request'

// 获取帖子列表
export function getPostList(params) {
  return request({
    url: '/community/posts',
    method: 'get',
    params
  })
}

// 获取帖子详情
export function getPostDetail(id) {
  return request({
    url: `/community/posts/${id}`,
    method: 'get'
  })
}

// 发布帖子
export function publishPost(data) {
  return request({
    url: '/community/posts',
    method: 'post',
    data
  })
}

// 点赞帖子
export function likePost(id) {
  return request({
    url: `/community/posts/${id}/like`,
    method: 'post'
  })
}

// 收藏帖子
export function collectPost(id) {
  return request({
    url: `/community/posts/${id}/collect`,
    method: 'post'
  })
}

// 获取评论列表
export function getComments(postId, params) {
  return request({
    url: `/community/posts/${postId}/comments`,
    method: 'get',
    params
  })
}

// 发表评论
export function addComment(data) {
  return request({
    url: '/community/comments',
    method: 'post',
    data
  })
}

// 删除评论
export function deleteComment(id) {
  return request({
    url: `/community/comments/${id}`,
    method: 'delete'
  })
}

// 获取热门帖子
export function getHotPosts(params) {
  return request({
    url: '/community/posts/hot',
    method: 'get',
    params
  })
}

// 获取精选成功案例
export function getSuccessCases(params) {
  return request({
    url: '/community/posts/success-cases',
    method: 'get',
    params
  })
}

// 获取高频维权场景
export function getFrequentScenarios() {
  return request({
    url: '/community/scenarios/frequent',
    method: 'get'
  })
}

// 搜索帖子
export function searchPosts(params) {
  return request({
    url: '/community/posts/search',
    method: 'get',
    params
  })
}

// 举报帖子
export function reportPost(id, data) {
  return request({
    url: `/community/posts/${id}/report`,
    method: 'post',
    data
  })
}

// 获取我的帖子
export function getMyPosts(params) {
  return request({
    url: '/community/posts/my',
    method: 'get',
    params
  })
}

// 获取我的收藏
export function getMyCollections(params) {
  return request({
    url: '/community/posts/collections',
    method: 'get',
    params
  })
}

// 删除帖子
export function deletePost(id) {
  return request({
    url: `/community/posts/${id}`,
    method: 'delete'
  })
}

// 更新帖子状态（已解决/求助中）
export function updatePostStatus(id, status) {
  return request({
    url: `/community/posts/${id}/status`,
    method: 'put',
    data: { status }
  })
}

// 点赞评论
export function likeComment(id) {
  return request({
    url: `/community/comments/${id}/like`,
    method: 'post'
  })
}

// 获取社区统计数据
export function getCommunityStats() {
  return request({
    url: '/community/stats',
    method: 'get'
  })
}
